﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SurveyCtrl.ascx.cs"
  Inherits="NguyenHoa.Web.Controls.SurveyCtrl" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dxcb" %>
<div class="question">
  <%=SurveyQuestion%></div>
<div class="assessment">
  <%=SurveyOptions %>
</div>
<div class="clear">
  <a class="btn" onclick="clearSurvey()"><span><strong>
    <%=GetGlobalResourceObject("Strings", "Cancel")%></a></strong></span><a class="btn btn_next"
      onclick="sendSurvey()"> <span><strong>
        <%=GetGlobalResourceObject("Strings", "Send")%></strong></span></a>
</div>
<asp:HiddenField ID="hfSurveyCheckbox" runat="server" />
<asp:HiddenField ID="hfIsSingleChoice" runat="server" />
<dxcb:ASPxCallback ID="surveyCallback" ClientInstanceName="surveyCallback" runat="server"
  OnCallback="surveyCallback_Callback">
  <ClientSideEvents CallbackComplete="function(s,e){onsurveyCallback_CallbackComplete(s,e);}" />
</dxcb:ASPxCallback>

<script type="text/javascript" language="javascript">
  function tickSurvey(choiceId, checked) {
    var choiceList = document.getElementById('<%=hfSurveyCheckbox.ClientID %>').value.split(';');
    var isSingleChoice = document.getElementById('<%=hfIsSingleChoice.ClientID %>').value;
    var newChoiceList = '';
    var isAdd = false;
    for (var i = 0; i < choiceList.length; i++) {
      if (choiceList[i] != '') {
        if (isSingleChoice == "true") {
          if (checked) {
            newChoiceList = choiceId + ';';
            isAdd = true;
          }
          continue;
        }
        if (choiceList[i] == choiceId) {
          if (checked) {
            newChoiceList += choiceList[i] + ';';
            isAdd = true;
            continue;
          }
          continue;
        }
        newChoiceList += choiceList[i] + ';';
      }
    }
    if (!isAdd && checked)
      newChoiceList += choiceId + ';';
    document.getElementById('<%=hfSurveyCheckbox.ClientID %>').value = newChoiceList;
  }

  function sendSurvey() {
    var choice = document.getElementById('<%=hfSurveyCheckbox.ClientID %>').value;
    if (choice == '') {
      alert('<%=GetGlobalResourceObject("Messages","ERR0041") %>');
    }
    else {
      pcWaiting.Show();
      surveyCallback.PerformCallback('Survey|');
    }
  }

  function clearSurvey() {
    var choiceList = document.getElementById('<%=hfSurveyCheckbox.ClientID %>').value.split(';');
    for (var i = 0; i < choiceList.length; i++) {
      var rdo = document.getElementById(choiceList[i]);
      if (rdo != null) {
        rdo.checked = false;
      }
    }
    document.getElementById('<%=hfSurveyCheckbox.ClientID %>').value = '';
  }

  function onsurveyCallback_CallbackComplete(s, e) {
    pcWaiting.Hide();
    var error = e.result;
    if (error != '') {
      alert(error);
    } else {
      alert('<%=GetGlobalResourceObject("Messages", "ERR0035") %>');
      clearSurvey();
    }
  }
</script>

